package src.controller;

import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class tuichu extends Application {

    @FXML
    private Button cancelButton;

    @FXML
    private Button confirmButton;

    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("../view/tuichu.fxml"));
        loader.setController(this); // 设置当前实例为控制器
        Parent root = loader.load();

        // 手动绑定事件（如果FXML中没有绑定）
        if (cancelButton != null) {
            cancelButton.setOnAction(event -> handleCancel());
        }
        if (confirmButton != null) {
            confirmButton.setOnAction(event -> handleConfirm());
        }

        primaryStage.setTitle("退出登录");
        primaryStage.setScene(new Scene(root, 300, 150));
        primaryStage.setResizable(false);
        primaryStage.show();
    }

    @FXML
    private void handleCancel() {
        System.out.println("取消按钮被点击");
        // 关闭当前窗口
        Stage stage = (Stage) cancelButton.getScene().getWindow();
        stage.close();
    }

    @FXML
    private void handleConfirm() {
        System.out.println("确定按钮被点击，退出应用");
        // 退出应用程序
        javafx.application.Platform.exit();
    }

    public static void main(String[] args) {
        launch(args);
    }
}